import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUi from 'element-ui'
import store from "./store"
import 'element-ui/lib/theme-chalk/index.css'
import 'font-awesome/css/font-awesome.css'
import 'tailwindcss/tailwind.css'
import 'animate.css';

import {deleteRequest, getRequest, postRequest, putRequest} from "@/utils/requestUtil";
import {initMenu} from "@/utils/menuUtil";
import api from "@/api";
import commonUtil from "@/utils/commonUtil";
import {downloadRequest} from "@/utils/download";

Vue.config.productionTip = false
Vue.use(ElementUi, {size: "small"})
Vue.prototype.postRequest = postRequest
Vue.prototype.getRequest = getRequest
Vue.prototype.putRequest = putRequest
Vue.prototype.deleteRequest = deleteRequest
Vue.prototype.downloadRequest = downloadRequest
Vue.prototype.api = api
Vue.prototype.commonUtil = commonUtil

//路由前置守卫
router.beforeEach( (to, from, next) => {
    //首先判断有token吗
    if (window.sessionStorage.getItem("token_login")) {
        //初始化菜单栏
        initMenu(router, store)
        next()
    } else {
        //判断路径是否是可用的
        if (to.path == "/") {
            next()
        } else {
            next("/?redirect=" + to.path)
        }
    }
})

const vue = new Vue({
    router,
    store,
    render: h => h(App),
}).$mount('#app')
export default vue